<template>
  <div class="supplier-silence">
    <c-table
      :data="tableData.pageData"
      :total="tableData.total"
      :columns="columns"
      :loading="tableLoading"
      @onReload="getSuppliers"
    >
      <template v-slot:header-l>
        <a-range-picker :ranges="preinstall" />
        <c-button type="primary" @click="exportData">导出</c-button>
      </template>
    </c-table>
  </div>
</template>

<script>
import moment from "moment";
import { getProviders } from "@/api/supplier";

const columns = [
  {
    title: "公司全称",
    dataIndex: "companyName"
  },
  {
    title: "联系人",
    dataIndex: "realName"
  },
  {
    title: "联系电话",
    dataIndex: "phone"
  },
  {
    title: "采购额度",
    scopedSlots: { customRender: "creditList" }
  },
  {
    title: "操作",
    scopedSlots: { customRender: "handle" }
  }
];

export default {
  data() {
    return {
      tableData: [],
      page: {
        num: 1,
        size: 20
      },
      tableLoading: false,
      columns,
      // 预设时间段
      preinstall: {
        最近30天: [
          moment()
            .startOf("day")
            .subtract(29, "days"),
          moment().endOf("day")
        ],
        最近60天: [
          moment()
            .startOf("day")
            .subtract(59, "days"),
          moment().endOf("day")
        ],
        最近90天: [
          moment()
            .startOf("day")
            .subtract(89, "days"),
          moment().endOf("day")
        ],
        最近180天: [
          moment()
            .startOf("day")
            .subtract(179, "days"),
          moment().endOf("day")
        ]
      }
    };
  },
  methods: {
    moment,
    // 导出数据
    exportData() {},
    // 查询供应商列表
    getSuppliers() {
      this.tableLoading = true;
      getProviders({
        pageData: {
          pageNum: this.page.num,
          pageSize: this.page.size
        }
      })
        .then(res => {
          this.tableData = res;
        })
        .finally(() => {
          this.tableLoading = false;
        });
    }
  },
  created() {
    this.getSuppliers();
  }
};
</script>
